<?php
/**
 * Created by PhpStorm.
 * User: THINK
 * Date: 2017/8/29
 * Time: 15:02
 */

namespace Admin\Controller;


use Think\Controller;

class RoleController extends Controller
{
    public function index(){
        $role=M('role');
        $roleinfo=$role->select();
        $count=$role->count();
        $this->assign('roleinfo',$roleinfo);
        $this->assign('count',$count);
        $this->display();
    }
    public function add(){
        if(!$_POST['sub']){
            $this->display();
        }else{
            $addrole=I('post.');
            $role=M('role');
            $roleinfo=$role->add($addrole);
            if ($roleinfo){
                $this->redirect('Role/index', '', 1, '添加成功！页面跳转中...');
            }else{
                echo "<script> alert('角色添加失败！')</script>";
            }
            $this->display();
        }
    }
    public function del(){
        $role = M('Role');
        $id = I('id');
        $count=$role->count();
        if ($role->delete($id)>0) {
            echo 1;
        }else{
            echo "<script>history.back();</script>";
        }

    }

}